import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';

import 'mixin/db_mixin.dart';
import 'package:timezone/data/latest.dart' as tz_data;

class GlobalBinding extends Bindings {
  @override
  void dependencies() {
    Get.put(Global());
  }
}

GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
final global = Get.find<Global>();

/// 全局静态数据
class Global extends GetxService with DbMixin {
  static Global get to => Get.put(Global());

  @override
  void onInit() {
    super.onInit();
    init();
  }

  /// 初始化
  Future init() async {
    SystemChrome.setPreferredOrientations(
        [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
    setSystemUi();
    // 初始化时区数据
    tz_data.initializeTimeZones();
  }

  void setSystemUi() {
    if (GetPlatform.isAndroid) {
      SystemUiOverlayStyle systemUiOverlayStyle = const SystemUiOverlayStyle(
        statusBarColor: Colors.transparent,
        statusBarBrightness: Brightness.light,
        statusBarIconBrightness: Brightness.dark,
        systemNavigationBarDividerColor: Colors.transparent,
        systemNavigationBarColor: Colors.white,
        systemNavigationBarIconBrightness: Brightness.dark,
      );
      SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
    }
  }
}
